package com.softer.wxzj.controller;

import com.github.pagehelper.PageInfo;
import com.softer.wxzj.common.aop.annotation.LogOperation;
import com.softer.wxzj.common.aop.enums.LogOperationType;
import com.softer.wxzj.common.aop.enums.LogOperationUnit;
import com.softer.wxzj.common.entity.CommonResult;
import com.softer.wxzj.common.entity.Page;
import com.softer.wxzj.common.util.ShiroUser;
import com.softer.wxzj.entity.SysUser;
import com.softer.wxzj.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
 * UserController class
 * @author zcz
 * @date 2019/1/16
 */
@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {
    @Autowired
    UserService userService;

    @RequestMapping("/add")
    public CommonResult add(SysUser user) {
        user.setCreater(ShiroUser.getUserName());
        return userService.insertUser(user);
    }
    @RequestMapping("/update")
    public CommonResult update(SysUser user) {
        return userService.update(user);
    }
    @RequestMapping("/delete")
    public CommonResult delete(String id) {
        return userService.delete(id);
    }
    @RequestMapping("/getList")
    @LogOperation(describe = "查询用户列表",operationUnit = LogOperationUnit.USER,operationType = LogOperationType.SELECT)
    public PageInfo<SysUser> getUserList(Page page, SysUser user) {
        return userService.getUserList(page,user);
    }

    @RequestMapping("/passwordReset")
    public CommonResult passwordReset(SysUser user) {
        return userService.resetPassword(user);
    }
}
